package com.zq.user.controller;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.zq.common.util.Result;
import com.zq.user.dao.dto.LoginDto;
import com.zq.user.dao.entity.UserInfo;
import com.zq.user.dao.entity.Users;
import com.zq.user.saconfig.UserStpUtil;
import com.zq.user.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * <p>
 * 用户表，用于存储系统用户信息 前端控制器
 * </p>
 * @author 张乔
 * @since 2025-04-27
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private IUsersService usersService;
//登录
@PostMapping("/login")
public Result<String> login(@RequestBody LoginDto loginDto) {
    String token = usersService.login(loginDto);
    return Result.successData(token);
}
//获取用户信息
@GetMapping("/getUserInfo")
    public Result<Object> getUserInfo(@RequestHeader("userToken")String userToken) {
  Users userInfo= usersService.getUserInfo(userToken);
        return Result.successData(userInfo);
    }



//用户注册
    @PostMapping("/register")
    public Result<String> register(@RequestBody Users users) {
usersService.register(users);

        return Result.success();

    }


    //修改用户头像
    @PostMapping("/updateAvatar")
    public Result<String> updateAvatar(MultipartFile file, @RequestHeader("userToken") String token){
        String url=    usersService.updateAvatar(file,token);
//        String url = minioService.uploadImage(minioProperties.getBucketName(),file);
        return Result.successData(url);
    }


//    客户退出
@GetMapping("/logout")
public Result<String> logout(@RequestHeader("userToken")String userToken) {

usersService.logout(userToken);
        return Result.success();
    }

//    修改用户信息

    @PostMapping("/updateUserInfo")
    public Result<String> updateUserInfo(@RequestBody Users users, @RequestHeader("userToken") String token) {
        usersService.updateUserInfo(users,token);
        return Result.success();
    }








}
